<?php
class wpConn{
	private $host;
	private $uname;
	private $upwd;
	private $dbname;
	private $charset;

	static $con;
	private function __construct($host,$uname,$upwd,$dbname,$charset){
		$this->host = $host;
		$this->uname = $uname;
		$this->upwd = $upwd;
		$this->dbname = $dbname;
		$this->charset = $charset;
		
		$this->connect();
	}
	
	private function connect(){
		$con=mysql_connect($this->host,$this->uname,$this->upwd);
		mysql_select_db($this->dbname);
		mysql_query("set names '{$this->charset}'");
		self::$con = $con;
	}
	
	public static function initdb($host='localhost',$uname='root',$upwd='',$dbname='abc',$charset='utf8'){
		if(!(self::$con instanceof self)){
			self::$con = new self($host,$uname,$upwd,$dbname,$charset);
		}
		return self::$con;
	}
	
	public function query($sql){
		$r = mysql_query($sql);
		$ret = array();
		while ($row=mysql_fetch_array($r)){
			$ret[] = $row;
		}
		return $ret;
	}
}